﻿@inject IHttpService _httpService
@inject NavigationManager NavigationManager
@inject IDataCacheService _dataCacheService


<CnGalWebSite.Components.Containers.MasaTitleContainer Outline Title="投票" Icon="@IconType.Vote.ToIconString()" ShowMoreButton OnClickMore="OnClickMore">
     <MSlideGroup ShowArrows="true" Class="slide-group-garp">
        <ChildContent>
            @foreach (var item in _dataCacheService.VoteCardsCatche)
            {
                <MSlideItem>
                    <div style="width:300px;">
                        <VoteViewTip Model="item" />
                    </div> 
                      
                </MSlideItem>
            }
        </ChildContent>

    </MSlideGroup>
</CnGalWebSite.Components.Containers.MasaTitleContainer>

@code {
    [CascadingParameter]
    public ErrorHandler ErrorHandler { get; set; }

    protected override async Task OnInitializedAsync()
    {

        try
        {
            if (_dataCacheService.VoteCardsCatche.Count == 0)
            {
                _dataCacheService.VoteCardsCatche = await _httpService.GetAsync<List<VoteCardViewModel>>("api/votes/GetVoteCards");
                _dataCacheService.VoteCardsCatche = _dataCacheService.VoteCardsCatche.OrderByDescending(s => s.EndTime).Take(12).ToList();

            }

        }
        catch (Exception ex)
        {
            await ErrorHandler.ProcessError(ex, "获取广场投票列表失败");
        }
    }
    public void OnClickMore()
    {
        NavigationManager.NavigateTo("/votes/home");
        
    }

}
